#pitchfx: functions for reading and analyzing Major League Baseball pitch data
#
#Peter Frase
#Started development May 2008
#Last update April 2009
#
#Routines for processing baseball pitchfx data
#Designed for data downloaded from the mlb web site:
#http://gd2.mlb.com/components/game/mlb/
#
#These functions are designed to be used in an environment with an open internet 
#connection and/or a local MySQL database. In addition to the data reading 
#functions, some of the plotting 
#commands query the internet in order to get data on the fly. However, offline 
#options have been provided so that analysis can be reproduced without access to 
#the MLB database.
#
#The main high level functions are:
#
#  get.pitches()  :   To retrieve data directly from either a local database or 
#                     the MLB website. This function, in turn, relies on  
#                     read.pitchfx() and its family of sub-functions.
#  
#  plot.pitchfx() :   To plot objects retrieved using get.pitches() 
#
#But the low level commands can be called directly as well.
#
# Constants:
#
#    mlbteams
#    
# Low level data retrieval commands:
#
#    getgames()
#    
#    getname()
#    
#    makeurl()
#    
#    read.pitchfx.gameinfo()
#    
#    read.pitchfx.gamestatus()
#    
#    read.pitchfx.getplayers()
#    
#    read.pitchfx.mysql()
#    
#    read.pitchfx.playersused()  
#
# Low level graphing commands (see documentation for plot.pitchfx()):
#
#    plot.pitchfx.count()
#    
#    plot.pitchfx.fastpolar()
#    
#    plot.pitchfx.hitzone()
#    
#    plot.pitchfx.nineman()
#
#    draw.truezone()
#
# Low level processing and analysis commands:
#
#    classify.pitches()
#    
#    clean.des()
#    
#    hit.zones()
#   
#    pitch.trajectory()
#    
#    pitchloc()
#    
#    selectivity.curve()
#    
#    shift()
#    
#    spin()
#    
#    strikeprob()    
#

require(arm)
require(boot)
require(polynom)

wd <- getwd()
setwd('~/pitchfx-svn/trunk')

#List of team identifiers used by MLB for pitchfx data--provided for reference
mlbteams<-c("ana","ari","atl","bal","bos","cha","chn","cin","cle","col","det",
            "flo","hou","kca","lan","mil","min","nya","nyn","oak","phi","pit",
            "sdn","sea","sln","sfn","tba","tex","tor","was")
 
#Data input functions 
source('read.pitchfx.r')

#Plotting functions
source('plot.pitchfx.r')

#Analysis functions
source('misc.pitchfx.r')

setwd(wd)
